package com.tom.architect.party3.day25.okhttp;

import java.util.HashMap;
import java.util.Map;

/**
 * 客户端请求
 */
public class Request {
    final String url;
    final Method method; //post,get
    final Map<String, String> headers;
    final RequestBody requestBody;

    public Request(Builder builder) {
        this.url = builder.url;
        this.method = builder.method;
        this.headers = builder.headers;
        this.requestBody = builder.requestBody;
    }

    public static class Builder {
        // 参数设置缓存。
        // url, body post参数，请求头
        String url;
        Method method; //post,get
        Map<String, String> headers;
        RequestBody requestBody; // post

        public Builder() {
            method = Method.GET; // 默认是get方法。
            headers = new HashMap();
        }

        public Request build() {
            return new Request(this);
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder get() {
            this.method = Method.GET;
            return this;
        }

        public Builder post(RequestBody requestBody) {
            this.method = Method.POST;
            this.requestBody = requestBody;
            return this;
        }

        public void header(String key, String value) {
            headers.put(key, value);
        }


    }
}
